
local U = require "packages/hanqing/util"

local bangshu = fk.CreateSkill{
  name = "hanqing__bangshu&",
  tags = { U.HorizontalAlliance, Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__bangshu&"] = "谤书",
  [":hanqing__bangshu&"] = "<a href='hanqing__alliance_skill'>连横技</a>，锁定技，"..
  "你的武将牌状态变化后，其他<a href='hanqing__alliance_href'>连横</a>角色弃一张牌。",
}

local spec = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(bangshu.name) and
      U.getAlliance(player) == "horizontal" and
      table.find(player.room:getOtherPlayers(player, false), function (p)
        return U.getAlliance(p) == "horizontal"
      end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if U.getAlliance(p) == "horizontal" and not p.dead then
        room:askToDiscard(p, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = "hanqing__bangshu",
          cancelable = false,
        })
      end
    end
  end,
}

bangshu:addEffect(fk.TurnedOver, spec)
bangshu:addEffect(fk.ChainStateChanged, spec)
bangshu:addEffect(U.HQAllianceChanged, spec)

return bangshu
